//
//  FRQNotificationsViewController.m
//  FRQBluetoothKit_Example
//
//  Created by admin on 2023/10/24.
//  Copyright © 2023 xuchunhai. All rights reserved.
//

#import "FRQNotificationsViewController.h"
#import "NotificationsViews.h"
@interface FRQNotificationsViewController ()
@property (nonatomic,strong) NotificationsViews *NotificationsView;
@end

@implementation FRQNotificationsViewController
- (NotificationsViews *)NotificationsView{
    if (nil==_NotificationsView) {
        _NotificationsView=skXibView(@"NotificationsViews");
        [self.view addSubview:_NotificationsView];
        [_NotificationsView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_topLayoutGuide);
            make.bottom.mas_equalTo(self.mas_bottomLayoutGuide);
            make.right.left.mas_equalTo(0);
        }];
        Boolean state=[skUser.push boolValue];
        if(state){
            [_NotificationsView.btnChange setImage:[UIImage imageNamed:@"ico_notifications_off"] forState:(UIControlStateNormal)];
        }else{
            [_NotificationsView.btnChange setImage:[UIImage imageNamed:@"ico_notifications_on"] forState:(UIControlStateNormal)];
        }
        @weakify(self)
        [[_NotificationsView.btnChange rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(__kindof UIControl * _Nullable x) {
            @strongify(self)
            
            [self changePushState];
        }];
    }
    
    return _NotificationsView;
}
//发送email验证码
- (void)changePushState {
    NSDictionary *dic=@{
    };
    [skNetTools skPOSTWithURL:[NSString stringWithFormat:@"%@%@",skURL,@"app/user/changePushState"] parameters:dic cachePolicy:0 callback:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
        NSLog(@"数据=%@",responseObject);
        skNetModel *model=responseObject;
        if(model.code==200){
            [self appUserInfo];
        }else{
            [SkToast SkToastShow:model.msg];
        }
        
    }];
}
-(void)appUserInfo{
    
    NSDictionary *dic=@{
    };
    [skNetTools skGETWithURL:[NSString stringWithFormat:@"%@%@",skURL,@"app/user/info"] parameters:dic cachePolicy:0 callback:^(id  _Nonnull responseObject, NSError * _Nonnull error) {
        NSLog(@"数据=%@",responseObject);
        skNetModel *model=[skNetModel mj_objectWithKeyValues:responseObject];
        if(model.code==200){
            [UserInfoModel mj_objectWithKeyValues:model.data];
            Boolean state=[skUser.push boolValue];
            if(state){
                [_NotificationsView.btnChange setImage:[UIImage imageNamed:@"ico_notifications_off"] forState:(UIControlStateNormal)];
            }else{
                [_NotificationsView.btnChange setImage:[UIImage imageNamed:@"ico_notifications_on"] forState:(UIControlStateNormal)];
            }
        }
    }];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title=@"Notifications";
    self.NotificationsView.hidden=NO;
    // Do any additional setup after loading the view.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
